package com.yaorange.jk.service.impl;

import com.yaorange.jk.dao.BaseDao;
import com.yaorange.jk.entity.Role;
import com.yaorange.jk.service.RoleService;
import com.yaorange.jk.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author coach tam
 * @date 2017/11/1
 */
@Service("roleService")
@Transactional
public class RoleServiceImpl implements RoleService {


    @Autowired
    private BaseDao<Role,String> roleDao;

    @Override
    @Transactional(readOnly = true)
    public Pagination findPage(int pageNo, int pageSize) {
        return roleDao.pageByHql("from Role",pageNo,pageSize);
    }


    @Override
    public List<Role> findAll() {
        return roleDao.getListByHQL("from Role");
    }

    @Override
    public void save(Role role) {



        roleDao.save(role);
    }

    @Override
    public Role findById(String id) {
        return roleDao.get(Role.class,id);
    }

    @Override
    public void update(Role model) {
        //根据主键查询出老数据
        Role oldRole = roleDao.get(Role.class,model.getId());
        oldRole.setName(model.getName());
        oldRole.setRemark(model.getRemark());
        roleDao.update(oldRole);
    }

    @Override
    public void deleteByIds(String[] ids) {
        for (String id :ids)
        {
            roleDao.deleteById(Role.class,id);
        }
    }

    @Override
    public void savaOrUpdate(Role opra_role) {
        roleDao.saveOrUpdate(opra_role);
    }
}
